<template>
  <div>
    <div class="topic-box">
      <div class="img-box" @click="goVideo">
        <a href="javascript:;">
          <img :src="searchInfo.image" alt="" />
          <div>
            <span>{{ timer }}</span>
          </div>
        </a>
      </div>
      <div class="text-box">
        <h3>
          <a href="javascript:;" @click="goVideo">{{ searchInfo.title }}</a>
        </h3>
        <div class="bot">
          <div class="icon">
            <p><span></span>{{ comment }}</p>
            <p><span></span>{{ searchInfo.like_num }}</p>
          </div>
          <p class="pingfen">
            评分：<span>{{ searchInfo.rating }}</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from "vuex";

export default {
  props: {
    searchInfo: {
      type: Object,
    }
  },
  name: "Searchlist",
  data(){
    return{
      comment:Math.floor(Math.random()*120),
      timer: 0,
    }
  },
  methods:{
    ...mapMutations(["setPostid"]),
    goVideo(){
      this.setPostid(this.searchInfo.postid);
      this.$router.push("/video");
    }
  },
  mounted(){
    let time = this.searchInfo.duration;
    let m = parseInt(time / 60);
    let s = parseInt(time % 60);
    m = m < 10 ? '0' + m : m;
    s = s < 10 ? '0' + s : s;
    this.timer = `${m}:${s}`
  }
};
</script>

<style lang="scss" scoped>
.topic-box {
  width: 272px;
  background-color: #fff;
  margin-bottom: 20px;
  .img-box {
    overflow: hidden;
    &:hover {
      img {
        transform: scale(1.1);
        transition: all 1.2s linear;
      }
    }
    a {
      position: relative;
      display: block;
      width: 272px;
      height: 181px;
      img {
        width: 272px;
        height: 181px;
        transition: all 1.2s linear;
      }
      div {
        position: absolute;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 40px;
        background-image: linear-gradient(
          to bottom,
          transparent,
          rgba(0, 0, 0, 0.4)
        );
        span {
          color: #fff;
          position: absolute;
          right: 6px;
          bottom: 4px;
        }
      }
    }
  }
  .text-box {
    position: relative;
    padding: 15px;
    h3 {
      height: 70px;
      a {
        font-size: 16px;
        color: #393939;
        font-weight: normal;
        line-height: 24px;
      }
    }
    .bot {
      display: flex;
      justify-content: space-between;
      width: 100%;
      .icon {
        display: flex;
        p {
          display: flex;
          align-items: center;
          font-size: 12px;
          color: #999;
          margin-right: 16px;
          span {
            width: 18px;
            height: 18px;
            display: inline-block;
            background-repeat: no-repeat;
            background-size: 100%;
            margin-right: 5px;
          }
        }
        p:nth-child(1) {
          span {
            background-image: url(https://www.vmovier.com/Public/Home/images/comment.png);
          }
        }
        p:nth-child(2) {
          span {
            background-image: url(https://www.vmovier.com/Public/Home/images/like.png);
          }
        }
      }
      .pingfen {
        font-size: 14px;
        color: #999;
        span {
          color: #f7b42c;
          font-weight: bold;
        }
      }
    }
  }
}
</style>